import { defineStore } from 'pinia'
import { ref } from 'vue'

type Phase = 'work' | 'shortBreak' | 'longBreak'

export const useConfigStore = defineStore('useConfigStore', () => {

    const config = ref({
        // 工作时长(单位:分钟)
        workTimer: 23,
        // 短休息(单位:分钟)
        shortBreakTimer: 5,
        // 长休息(单位:分钟)
        longBreakTimer: 15,
    }) 
    
    // 根据阶段获取总秒数
    const getPhaseSeconds = (phase: Phase): number => {
        let totalTime = 0
        switch (phase) {
            case 'work': totalTime = config.value.workTimer; break
            case 'shortBreak': totalTime = config.value.shortBreakTimer; break
            case 'longBreak': totalTime = config.value.longBreakTimer; break
        }
        return totalTime * 60
    }
    
    return { config, getPhaseSeconds }
}, {
    persist: true
})